﻿using System.Diagnostics;
using System.Reflection;

namespace SlamCms.Web.Mvc
{
	public class SlamCmsPrecompiledViewEngine : PrecompiledMvcEngine
	{
		public SlamCmsPrecompiledViewEngine(Assembly assembly)
			: this(assembly, null)
		{
		}

		public SlamCmsPrecompiledViewEngine(Assembly assembly, string baseVirtualPath)
			: base(assembly, baseVirtualPath)
		{
			base.AreaViewLocationFormats = new[] 
			{ 
				"~/Areas/{2}/Views/{1}/DisplayTemplates/{0}.cshtml", 
				"~/Areas/{2}/Views/{1}/{0}.cshtml", 
				"~/Areas/{2}/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/{2}/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.AreaMasterLocationFormats = new[] 
			{ 
				"~/Areas/{2}/Views/{1}/DisplayTemplates/{0}.cshtml", 
				"~/Areas/{2}/Views/{1}/{0}.cshtml", 
				"~/Areas/{2}/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/{2}/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.AreaPartialViewLocationFormats = new[] 
			{ 
				"~/Areas/{2}/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/{2}/Views/{1}/{0}.cshtml",
				"~/Areas/{2}/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/{2}/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.ViewLocationFormats = new[] 
			{ 
				"~/Views/{1}/DisplayTemplates/{0}.cshtml", 
				"~/Views/{1}/{0}.cshtml", 
				"~/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.MasterLocationFormats = new[] 
			{ 
				"~/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Views/{1}/{0}.cshtml",
				"~/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.PartialViewLocationFormats = new[] 
			{ 
				"~/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Views/{1}/{0}.cshtml",
				"~/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Views/Shared/{0}.cshtml",
				"~/Areas/_default/Views/{1}/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/{1}/{0}.cshtml",
				"~/Areas/_default/Views/Shared/DisplayTemplates/{0}.cshtml",
				"~/Areas/_default/Views/Shared/{0}.cshtml"
			};

			base.FileExtensions = new[] { "cshtml" };
		}

		//public override System.Web.Mvc.ViewEngineResult FindPartialView(System.Web.Mvc.ControllerContext controllerContext, string partialViewName, bool useCache)
		//{
		//    Debug.Print("");
		//    return base.FindPartialView(controllerContext, partialViewName, useCache);
		//}
	}
}
